/** vfork*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<signal.h>

static void sig_handler(int sig)
{
	printf("received signal:%d,pid:%d,pgid:%d\n",sig,getpid(),getpgrp());
}

int main(void)
{
	struct sigaction sig={0};
	int ret;
	sig.sa_handler=sig_handler;
	sig.sa_flags=0;
	sigemptyset(&sig.sa_mask);
	ret=sigaction(SIGINT,&sig,NULL);
	if(-1==ret){
		perror("sigaction error");
		exit(-1);
	}
	switch(fork()){
		case -1:
			perror("fork error");
			return 1;
		case 0:
			printf("i am child process,pid:%d,getpgrp:%d,getsid:%d\n",getpid(),getpgrp(),getsid(0));
			while(1)
				sleep(1);
			_exit(0);
		default:
			printf("i am parent process,pid:%d,getpgrp:%d,getsid:%d\n",getpid(),getpgrp(),getsid(0));
			while(1)
				sleep(1);
			break;
	}
	exit(0);
}
